Socket
Socket
Sign inDemoInstall

thunky

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thunky

delay the evaluation of a paramless async function and cache the result


Version published
Weekly downloads
11M
increased by5.7%
Maintainers
1
Weekly downloads
 
Created

What is thunky?

The thunky npm package is designed to delay a function's execution until it's actually needed. It wraps a function in a way that ensures it is only called once, regardless of how many times the wrapper is invoked. This is particularly useful for initialization functions that you don't want to run multiple times or expensive operations that should be deferred until absolutely necessary.

What are thunky's main functionalities?

Lazy initialization

This feature allows for the lazy initialization of resources. The provided code sample demonstrates how a potentially expensive operation (simulated with a setTimeout) is wrapped in a thunky function. Despite calling 'load' twice, the initialization code only runs once, and both calls receive the result once it's available.

const thunky = require('thunky');
let load = thunky((callback) => {
  console.log('Initializing...');
  setTimeout(() => callback(null, 'Initialization complete'), 1000);
});

load((err, message) => console.log(message));
load((err, message) => console.log(message));

Other packages similar to thunky

Keywords

FAQs

Package last updated on 06 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc